﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiArte.Data.Catalog
{
    public class AttributeDal : BaseDal
    {
        /// <summary>
        /// Deletes all attributes
        /// </summary>
        public void DeleteAll()
        {
            using (var command = new Npgsql.NpgsqlCommand("DELETE FROM attribute"))
                PerformCommand(command);
        }

        /// <summary>
        /// Inserts a new attribute
        /// </summary>
        /// <param name="type">The attribute type</param>
        /// <returns>The insert attribute id</returns>
        public int Insert(String type)
        {
            using (var command = new Npgsql.NpgsqlCommand("INSERT INTO attribute(attribute_id, type) VALUES " +
                "(nextval('attribute_id_sequence'), :type) RETURNING attribute_id"))
            {
                command.Parameters.AddWithValue("type", type);

                return PerformInsertCommandAndGetReturningValue(command);
            }
        }

    }
}
